package com.atguigu.gmall.list.listener;

import com.atguigu.gmall.constant.MqConst;
import com.atguigu.gmall.list.service.ListService;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 接收消息
 */
@Component
public class Consumer {

    @Autowired
    private ListService listService;
    //接收  添加索引（上架）
    //@RabbitListener(queues = {MqConst.QUEUE_GOODS_UPPER})
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange(value = MqConst.EXCHANGE_DIRECT_GOODS),
            value = @Queue(value = MqConst.QUEUE_GOODS_UPPER,durable = "true",autoDelete = "false"),
            key = MqConst.ROUTING_GOODS_UPPER
    ))
    public void upperGoods(Long skuId){
        //添加索引
        listService.upperGoods(skuId);
    }
    //接收  删除索引 （下架）
    @RabbitListener(bindings = @QueueBinding(
            exchange = @Exchange(value = MqConst.EXCHANGE_DIRECT_GOODS),
            value = @Queue(value = MqConst.QUEUE_GOODS_LOWER,durable = "true",autoDelete = "false"),
            key = MqConst.ROUTING_GOODS_LOWER
    ))
    public void lowerGoods(Long skuId){
        //删除索引
        listService.lowerGoods(skuId);
    }
}
